package com.hzqx.syndata.hzqx.utils;

import java.io.*;
import java.text.ParseException;
public class TestIo {
    /**
     * 这是一个main方法。
     * @param args
     * @throws IOException
     */
    public static void main1(String[] args) throws IOException {
        String str=new String();
        InputStream in=new FileInputStream(new File("F:\\t.txt"));
        byte[] bytes=new byte[1024];
        int i=0;
        while ((i=in.read(bytes))!=-1){
            str+=new String(bytes,0,i);
        }
        in.close();
    }

    /**
     * BufferInputStream是一个字节缓冲流，读取的速率能远远大于FileInputStream,对应大文件会有很明显的效果
     * main方法
     * @param args
     * @throws IOException
     * @throws ParseException
     */
    public static void main2(String[] args) throws IOException, ParseException {
        String str="www.baidu.com";
        InputStream in=new FileInputStream("D:\\d.txt");
        BufferedInputStream bufer=new BufferedInputStream(in);
        OutputStream out=new FileOutputStream("D:\\w.txt");
        byte[] bytes=new byte[1024];
        int len=0;
        while ((len=bufer.read())!=-1){
            out.write(len);
        }
        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException, ParseException {
        String str=new String();
        InputStream in = new FileInputStream(new File("D:\\d.txt"));
        BufferedInputStream buffered=new BufferedInputStream(in);
        byte[] bytes=new byte[1024];
        int i=0;
        while ((i=buffered.read(bytes))!=-1){
            str += new String(bytes,0,i);
        }
        System.out.println(str);
        in.close();
        buffered.close();
    }
}
